
const query = require('../utils/DB')
class categoryModel {
	// 获取分类列表
	static async getCategoryList(
		nowPage = 1,
		pageSize = 10
	) {
		let start = (nowPage - 1) * pageSize
		let listCount = await query(`select count(*) as num from category`)
		let list =await query(
			`select * from category  limit ${start},${pageSize}`)
		return {
			count: listCount[0].num,
			list: list
		}
	}
	// 添加分类
	static addCategory(name, status) {
		return query(`INSERT INTO category(name,  status) VALUES ('${name}',  ${status})`)
	}

	// 修改分类
	static editCategory(id, name, status) {
		return query(`UPDATE category SET name='${name}',status=${status} WHERE id = ${id}`)
	}

	// 删除分类
	static delCategory(id) {
		return query(`delete from category where id=${id}`)
	}


}
module.exports = categoryModel